<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sodium</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="class.rnpffi.html">« RnpFFI</a></li>
      <li style="float: right;"><a href="intro.sodium.html">简介 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="refs.crypto.html">加密扩展</a></li>
    <li>Sodium</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="book.sodium" class="book">
 
 <h1 class="title">Sodium</h1>
 

 

 






 






 






 





<ul class="chunklist chunklist_book"><li><a href="intro.sodium.html">简介</a></li><li><a href="sodium.setup.html">安装/配置</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="sodium.requirements.html">需求</a></li><li><a href="sodium.installation.html">安装</a></li><li><a href="sodium.configuration.html">运行时配置</a></li><li><a href="sodium.resources.html">资源类型</a></li></ul></li><li><a href="sodium.constants.html">预定义常量</a></li><li><a href="ref.sodium.html">Sodium 函数</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="function.sodium-add.html">sodium_add</a> — Add large numbers</li><li><a href="function.sodium-base642bin.html">sodium_base642bin</a> — Decodes a base64-encoded string into raw binary.</li><li><a href="function.sodium-bin2base64.html">sodium_bin2base64</a> — Encodes a raw binary string with base64.</li><li><a href="function.sodium-bin2hex.html">sodium_bin2hex</a> — Encode to hexadecimal</li><li><a href="function.sodium-compare.html">sodium_compare</a> — Compare large numbers</li><li><a href="function.sodium-crypto-aead-aes256gcm-decrypt.html">sodium_crypto_aead_aes256gcm_decrypt</a> — Verify then decrypt a message with AES-256-GCM</li><li><a href="function.sodium-crypto-aead-aes256gcm-encrypt.html">sodium_crypto_aead_aes256gcm_encrypt</a> — Encrypt then authenticate with AES-256-GCM</li><li><a href="function.sodium-crypto-aead-aes256gcm-is-available.html">sodium_crypto_aead_aes256gcm_is_available</a> — Check if hardware supports AES256-GCM</li><li><a href="function.sodium-crypto-aead-aes256gcm-keygen.html">sodium_crypto_aead_aes256gcm_keygen</a> — Generate a random AES-256-GCM key</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-decrypt.html">sodium_crypto_aead_chacha20poly1305_decrypt</a> — Verify then decrypt with ChaCha20-Poly1305</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-encrypt.html">sodium_crypto_aead_chacha20poly1305_encrypt</a> — Encrypt then authenticate with ChaCha20-Poly1305</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-ietf-decrypt.html">sodium_crypto_aead_chacha20poly1305_ietf_decrypt</a> — Verify that the ciphertext includes a valid tag</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-ietf-encrypt.html">sodium_crypto_aead_chacha20poly1305_ietf_encrypt</a> — Encrypt a message</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-ietf-keygen.html">sodium_crypto_aead_chacha20poly1305_ietf_keygen</a> — Generate a random ChaCha20-Poly1305 (IETF) key.</li><li><a href="function.sodium-crypto-aead-chacha20poly1305-keygen.html">sodium_crypto_aead_chacha20poly1305_keygen</a> — Generate a random ChaCha20-Poly1305 key.</li><li><a href="function.sodium-crypto-aead-xchacha20poly1305-ietf-decrypt.html">sodium_crypto_aead_xchacha20poly1305_ietf_decrypt</a> — (Preferred) Verify then decrypt with XChaCha20-Poly1305</li><li><a href="function.sodium-crypto-aead-xchacha20poly1305-ietf-encrypt.html">sodium_crypto_aead_xchacha20poly1305_ietf_encrypt</a> — (Preferred) Encrypt then authenticate with XChaCha20-Poly1305</li><li><a href="function.sodium-crypto-aead-xchacha20poly1305-ietf-keygen.html">sodium_crypto_aead_xchacha20poly1305_ietf_keygen</a> — Generate a random XChaCha20-Poly1305 key.</li><li><a href="function.sodium-crypto-auth-keygen.html">sodium_crypto_auth_keygen</a> — Generate a random key for sodium_crypto_auth</li><li><a href="function.sodium-crypto-auth-verify.html">sodium_crypto_auth_verify</a> — Verifies that the tag is valid for the message</li><li><a href="function.sodium-crypto-auth.html">sodium_crypto_auth</a> — Compute a tag for the message</li><li><a href="function.sodium-crypto-box-keypair-from-secretkey-and-publickey.html">sodium_crypto_box_keypair_from_secretkey_and_publickey</a> — Create a unified keypair string from a secret key and public key</li><li><a href="function.sodium-crypto-box-keypair.html">sodium_crypto_box_keypair</a> — Randomly generate a secret key and a corresponding public key</li><li><a href="function.sodium-crypto-box-open.html">sodium_crypto_box_open</a> — Authenticated public-key decryption</li><li><a href="function.sodium-crypto-box-publickey-from-secretkey.html">sodium_crypto_box_publickey_from_secretkey</a> — Calculate the public key from a secret key</li><li><a href="function.sodium-crypto-box-publickey.html">sodium_crypto_box_publickey</a> — Extract the public key from a crypto_box keypair</li><li><a href="function.sodium-crypto-box-seal-open.html">sodium_crypto_box_seal_open</a> — Anonymous public-key decryption</li><li><a href="function.sodium-crypto-box-seal.html">sodium_crypto_box_seal</a> — Anonymous public-key encryption</li><li><a href="function.sodium-crypto-box-secretkey.html">sodium_crypto_box_secretkey</a> — Extracts the secret key from a crypto_box keypair</li><li><a href="function.sodium-crypto-box-seed-keypair.html">sodium_crypto_box_seed_keypair</a> — Deterministically derive the key pair from a single key</li><li><a href="function.sodium-crypto-box.html">sodium_crypto_box</a> — Authenticated public-key encryption</li><li><a href="function.sodium-crypto-core-ristretto255-add.html">sodium_crypto_core_ristretto255_add</a> — Adds an element</li><li><a href="function.sodium-crypto-core-ristretto255-from-hash.html">sodium_crypto_core_ristretto255_from_hash</a> — Maps a vector</li><li><a href="function.sodium-crypto-core-ristretto255-is-valid-point.html">sodium_crypto_core_ristretto255_is_valid_point</a> — Determines if a point on the ristretto255 curve</li><li><a href="function.sodium-crypto-core-ristretto255-random.html">sodium_crypto_core_ristretto255_random</a> — Generates a random key</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-add.html">sodium_crypto_core_ristretto255_scalar_add</a> — Adds a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-complement.html">sodium_crypto_core_ristretto255_scalar_complement</a> — The sodium_crypto_core_ristretto255_scalar_complement purpose</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-invert.html">sodium_crypto_core_ristretto255_scalar_invert</a> — Inverts a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-mul.html">sodium_crypto_core_ristretto255_scalar_mul</a> — Multiplies a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-negate.html">sodium_crypto_core_ristretto255_scalar_negate</a> — Negates a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-random.html">sodium_crypto_core_ristretto255_scalar_random</a> — Generates a random key</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-reduce.html">sodium_crypto_core_ristretto255_scalar_reduce</a> — Reduces a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-scalar-sub.html">sodium_crypto_core_ristretto255_scalar_sub</a> — Subtracts a scalar value</li><li><a href="function.sodium-crypto-core-ristretto255-sub.html">sodium_crypto_core_ristretto255_sub</a> — Subtracts an element</li><li><a href="function.sodium-crypto-generichash-final.html">sodium_crypto_generichash_final</a> — Complete the hash</li><li><a href="function.sodium-crypto-generichash-init.html">sodium_crypto_generichash_init</a> — Initialize a hash for streaming</li><li><a href="function.sodium-crypto-generichash-keygen.html">sodium_crypto_generichash_keygen</a> — Generate a random generichash key</li><li><a href="function.sodium-crypto-generichash-update.html">sodium_crypto_generichash_update</a> — Add message to a hash</li><li><a href="function.sodium-crypto-generichash.html">sodium_crypto_generichash</a> — Get a hash of the message</li><li><a href="function.sodium-crypto-kdf-derive-from-key.html">sodium_crypto_kdf_derive_from_key</a> — Derive a subkey</li><li><a href="function.sodium-crypto-kdf-keygen.html">sodium_crypto_kdf_keygen</a> — Generate a random root key for the KDF interface</li><li><a href="function.sodium-crypto-kx-client-session-keys.html">sodium_crypto_kx_client_session_keys</a> — Calculate the client-side session keys.</li><li><a href="function.sodium-crypto-kx-keypair.html">sodium_crypto_kx_keypair</a> — Creates a new sodium keypair</li><li><a href="function.sodium-crypto-kx-publickey.html">sodium_crypto_kx_publickey</a> — Extract the public key from a crypto_kx keypair</li><li><a href="function.sodium-crypto-kx-secretkey.html">sodium_crypto_kx_secretkey</a> — Extract the secret key from a crypto_kx keypair.</li><li><a href="function.sodium-crypto-kx-seed-keypair.html">sodium_crypto_kx_seed_keypair</a> — Description</li><li><a href="function.sodium-crypto-kx-server-session-keys.html">sodium_crypto_kx_server_session_keys</a> — Calculate the server-side session keys.</li><li><a href="function.sodium-crypto-pwhash-scryptsalsa208sha256-str-verify.html">sodium_crypto_pwhash_scryptsalsa208sha256_str_verify</a> — Verify that the password is a valid password verification string</li><li><a href="function.sodium-crypto-pwhash-scryptsalsa208sha256-str.html">sodium_crypto_pwhash_scryptsalsa208sha256_str</a> — Get an ASCII encoded hash</li><li><a href="function.sodium-crypto-pwhash-scryptsalsa208sha256.html">sodium_crypto_pwhash_scryptsalsa208sha256</a> — Derives a key from a password, using scrypt</li><li><a href="function.sodium-crypto-pwhash-str-needs-rehash.html">sodium_crypto_pwhash_str_needs_rehash</a> — Determine whether or not to rehash a password</li><li><a href="function.sodium-crypto-pwhash-str-verify.html">sodium_crypto_pwhash_str_verify</a> — Verifies that a password matches a hash</li><li><a href="function.sodium-crypto-pwhash-str.html">sodium_crypto_pwhash_str</a> — Get an ASCII-encoded hash</li><li><a href="function.sodium-crypto-pwhash.html">sodium_crypto_pwhash</a> — Derive a key from a password, using Argon2</li><li><a href="function.sodium-crypto-scalarmult-base.html">sodium_crypto_scalarmult_base</a> — 别名 sodium_crypto_box_publickey_from_secretkey</li><li><a href="function.sodium-crypto-scalarmult-ristretto255-base.html">sodium_crypto_scalarmult_ristretto255_base</a> — Calculates the public key from a secret key</li><li><a href="function.sodium-crypto-scalarmult-ristretto255.html">sodium_crypto_scalarmult_ristretto255</a> — Computes a shared secret</li><li><a href="function.sodium-crypto-scalarmult.html">sodium_crypto_scalarmult</a> — Compute a shared secret given a user's secret key and another user's public key</li><li><a href="function.sodium-crypto-secretbox-keygen.html">sodium_crypto_secretbox_keygen</a> — Generate random key for sodium_crypto_secretbox</li><li><a href="function.sodium-crypto-secretbox-open.html">sodium_crypto_secretbox_open</a> — Authenticated shared-key decryption</li><li><a href="function.sodium-crypto-secretbox.html">sodium_crypto_secretbox</a> — Authenticated shared-key encryption</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-init-pull.html">sodium_crypto_secretstream_xchacha20poly1305_init_pull</a> — Initialize a secretstream context for decryption</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-init-push.html">sodium_crypto_secretstream_xchacha20poly1305_init_push</a> — Initialize a secretstream context for encryption</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-keygen.html">sodium_crypto_secretstream_xchacha20poly1305_keygen</a> — Generate a random secretstream key.</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-pull.html">sodium_crypto_secretstream_xchacha20poly1305_pull</a> — Decrypt a chunk of data from an encrypted stream</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-push.html">sodium_crypto_secretstream_xchacha20poly1305_push</a> — Encrypt a chunk of data so that it can safely be decrypted in a streaming API</li><li><a href="function.sodium-crypto-secretstream-xchacha20poly1305-rekey.html">sodium_crypto_secretstream_xchacha20poly1305_rekey</a> — Explicitly rotate the key in the secretstream state</li><li><a href="function.sodium-crypto-shorthash-keygen.html">sodium_crypto_shorthash_keygen</a> — Get random bytes for key</li><li><a href="function.sodium-crypto-shorthash.html">sodium_crypto_shorthash</a> — Compute a short hash of a message and key</li><li><a href="function.sodium-crypto-sign-detached.html">sodium_crypto_sign_detached</a> — Sign the message</li><li><a href="function.sodium-crypto-sign-ed25519-pk-to-curve25519.html">sodium_crypto_sign_ed25519_pk_to_curve25519</a> — Convert an Ed25519 public key to a Curve25519 public key</li><li><a href="function.sodium-crypto-sign-ed25519-sk-to-curve25519.html">sodium_crypto_sign_ed25519_sk_to_curve25519</a> — Convert an Ed25519 secret key to a Curve25519 secret key</li><li><a href="function.sodium-crypto-sign-keypair-from-secretkey-and-publickey.html">sodium_crypto_sign_keypair_from_secretkey_and_publickey</a> — Join a secret key and public key together</li><li><a href="function.sodium-crypto-sign-keypair.html">sodium_crypto_sign_keypair</a> — Randomly generate a secret key and a corresponding public key</li><li><a href="function.sodium-crypto-sign-open.html">sodium_crypto_sign_open</a> — Check that the signed message has a valid signature</li><li><a href="function.sodium-crypto-sign-publickey-from-secretkey.html">sodium_crypto_sign_publickey_from_secretkey</a> — Extract the Ed25519 public key from the secret key</li><li><a href="function.sodium-crypto-sign-publickey.html">sodium_crypto_sign_publickey</a> — Extract the Ed25519 public key from a keypair</li><li><a href="function.sodium-crypto-sign-secretkey.html">sodium_crypto_sign_secretkey</a> — Extract the Ed25519 secret key from a keypair</li><li><a href="function.sodium-crypto-sign-seed-keypair.html">sodium_crypto_sign_seed_keypair</a> — Deterministically derive the key pair from a single key</li><li><a href="function.sodium-crypto-sign-verify-detached.html">sodium_crypto_sign_verify_detached</a> — Verify signature for the message</li><li><a href="function.sodium-crypto-sign.html">sodium_crypto_sign</a> — Sign a message</li><li><a href="function.sodium-crypto-stream-keygen.html">sodium_crypto_stream_keygen</a> — Generate a random sodium_crypto_stream key.</li><li><a href="function.sodium-crypto-stream-xchacha20-keygen.html">sodium_crypto_stream_xchacha20_keygen</a> — Returns a secure random key</li><li><a href="function.sodium-crypto-stream-xchacha20-xor-ic.html">sodium_crypto_stream_xchacha20_xor_ic</a> — Encrypts a message using a nonce and a secret key (no authentication)</li><li><a href="function.sodium-crypto-stream-xchacha20-xor.html">sodium_crypto_stream_xchacha20_xor</a> — Encrypts a message using a nonce and a secret key (no authentication)</li><li><a href="function.sodium-crypto-stream-xchacha20.html">sodium_crypto_stream_xchacha20</a> — Expands the key and nonce into a keystream of pseudorandom bytes</li><li><a href="function.sodium-crypto-stream-xor.html">sodium_crypto_stream_xor</a> — Encrypt a message without authentication</li><li><a href="function.sodium-crypto-stream.html">sodium_crypto_stream</a> — Generate a deterministic sequence of bytes from a seed</li><li><a href="function.sodium-hex2bin.html">sodium_hex2bin</a> — Decodes a hexadecimally encoded binary string</li><li><a href="function.sodium-increment.html">sodium_increment</a> — Increment large number</li><li><a href="function.sodium-memcmp.html">sodium_memcmp</a> — Test for equality in constant-time</li><li><a href="function.sodium-memzero.html">sodium_memzero</a> — Overwrite a string with NUL characters</li><li><a href="function.sodium-pad.html">sodium_pad</a> — Add padding data</li><li><a href="function.sodium-unpad.html">sodium_unpad</a> — Remove padding data</li></ul></li><li><a href="class.sodiumexception.html">SodiumException</a> — The SodiumException class</li></ul></div></div></div></body></html>